<?php
/**
 * 销售出库单
 * Created by PhpStorm.
 * User: echa
 * Date: 2018/1/31
 * Time: 17:36
 *
 */
namespace App\Services\Warehouse;


class SalesReleaseService extends PublicService {

    //销售出库表单ID
    //protected $Formid = 'SAL_OUTSTOCK';

    public function __construct()
    {
        parent::__construct(Config('k3cloud.SalesRelease'));
    }

    /**
     * 保存
     * 1.formid：业务对象表单Id（必录）
     * 2.data：Json格式数据（详情参考Json格式数据）（必录）
     * 2.1.Creator：创建者名字（非必录）
     * 2.2.NeedUpDateFields：需要保存的字段,格式["fieldkey1","fieldkey2","entitykey1",...]，数组类型(非必录)
     * 2.3.NeedReturnFields：需要返回的结果字段,格式["fieldkey","entitykey.fieldkey",...]（非必录）
     * 2.4.IsDeleteEntry：是否删除分录，默认True删除（非必录）
     * 2.5.SubSystemId：菜单所在子系统Id（非必录）
     * 2.6.IsVerifyBaseDataField：是否验证所有的基础资料，默认False不验证（非必录）
     * 2.7.IsEntryBatchFill：是否批量填充分录：默认为Ture（非必录）
     * 2.8.Model：表单实体数据（必录）
     */
    public function SaveSalesRelease($arrdata = [])
    {
            $data = [
                    "FID"=>"0",
                    "FBillTypeID"=>[
                        "FNumber"=>"XSCKD01_SYS"
                    ],
                    "FBillNo"=>"",
                    "FDate"=>"2018-01-3100=>00=>00",
                    "FSaleOrgId"=>[
                        "FNumber"=>"100"
                    ],
                    "FSaleDeptID"=>[
                        "FNumber"=>""
                    ],
                    "FCustomerID"=>[
                        "FNumber"=>"CUST0002"
                    ],
                    "FHeadLocationId"=>[
                        "FNUMBER"=>""
                    ],
                    "FCorrespondOrgId"=>[
                        "FNumber"=>""
                    ],
                    "FCarrierID"=>[
                        "FNumber"=>""
                    ],
                    "FCarriageNO"=>"",
                    "FSalesGroupID"=>[
                        "FNumber"=>""
                    ],
                    "FSalesManID"=>[
                        "FNumber"=>""
                    ],
                    "FStockOrgId"=>[
                        "FNumber"=>"100"
                    ],
                    "FDeliveryDeptID"=>[
                        "FNumber"=>""
                    ],
                    "FStockerGroupID"=>[
                        "FNumber"=>""
                    ],
                    "FStockerID"=>[
                        "FNumber"=>""
                    ],
                    "FNote"=>"",
                    "FReceiverID"=>[
                        "FNumber"=>"CUST0002"
                    ],
                    "FReceiveAddress"=>"",
                    "FSettleID"=>[
                        "FNumber"=>"CUST0002"
                    ],
                    "FReceiverContactID"=>[
                        "FName"=>""
                    ],
                    "FPayerID"=>[
                        "FNumber"=>"CUST0002"
                    ],
                    "FOwnerTypeIdHead"=>"BD_OwnerOrg",
                    "FOwnerIdHead"=>[
                        "FNumber"=>""
                    ],
                    "FScanBox"=>"",
                    "FCDateOffsetUnit"=>"",
                    "FCDateOffsetValue"=>0,
                    "FPlanRecAddress"=>"",
                    "FIsTotalServiceOrCost"=>false,
                    "SubHeadEntity"=>[
                        "FSettleCurrID"=>[
                            "FNumber"=>"PRE001"
                        ],
                        "FThirdBillNo"=>"",
                        "FThirdBillId"=>"",
                        "FThirdSrcType"=>"",
                        "FSettleOrgID"=>[
                            "FNumber"=>"100"
                        ],
                        "FSettleTypeID"=>[
                            "FNumber"=>""
                        ],
                        "FReceiptConditionID"=>[
                            "FNumber"=>""
                        ],
                        "FPriceListId"=>[
                            "FNumber"=>""
                        ],
                        "FDiscountListId"=>[
                            "FNumber"=>""
                        ],
                        "FIsIncludedTax"=>true,
                        "FLocalCurrID"=>[
                            "FNumber"=>"PRE001"
                        ],
                        "FExchangeTypeID"=>[
                            "FNumber"=>"HLTX01_SYS"
                        ],
                        "FExchangeRate"=>1.0,
                        "FIsPriceExcludeTax"=>true
                    ],
                    "FEntity"=>[
                        [
                            "FENTRYID"=>null,
                            "FRowType"=>"Standard",
                            "FCustMatID"=>[
                                "FNumber"=>""
                            ],
                            "FMaterialID"=>[
                                "FNumber"=>"0080687504565"
                            ],
                            "FUnitID"=>[
                                "FNumber"=>"盒"
                            ],
                            "FInventoryQty"=>0.0,
                            "FParentMatId"=>[
                                "FNumber"=>""
                            ],
                            "FRealQty"=>2.0,
                            "FDisPriceQty"=>0.0,
                            "FPrice"=>0.0,
                            "FTaxPrice"=>0.0,
                            "FIsFree"=>false,
                            "FBomID"=>[
                                "FNumber"=>""
                            ],
                            "FProduceDate"=>null,
                            "FOwnerTypeID"=>"BD_OwnerOrg",
                            "FOwnerID"=>[
                                "FNumber"=>"100"
                            ],
                            "FLot"=>[
                                "FNumber"=>""
                            ],
                            "FExpiryDate"=>null,
                            "FTaxCombination"=>[
                                "FNumber"=>""
                            ],
                            "FEntryTaxRate"=>17.00,
                            "FAuxUnitQty"=>0.0,
                            "FExtAuxUnitId"=>[
                                "FNumber"=>""
                            ],
                            "FExtAuxUnitQty"=>0.0,
                            "FStockID"=>[
                                "FNumber"=>"CK001"
                            ],
                            "FStockStatusID"=>[
                                "FNumber"=>"KCZT01_SYS"
                            ],
                            "FQualifyType"=>"",
                            "FMtoNo"=>null,
                            "FEntrynote"=>null,
                            "FDiscountRate"=>0.0,
                            "FActQty"=>0.0,
                            "FSalUnitID"=>[
                                "FNumber"=>"盒"
                            ],
                            "FSALUNITQTY"=>2.0,
                            "FSALBASEQTY"=>2.0,
                            "FPRICEBASEQTY"=>2.0,
                            "FProjectNo"=>null,
                            "FOUTCONTROL"=>false,
                            "FRepairQty"=>0.0,
                            "FIsCreateProDoc"=>"",
                            "FEOwnerSupplierId"=>[
                                "FNumber"=>""
                            ],
                            "FIsOverLegalOrg"=>false,
                            "FESettleCustomerId"=>[
                                "FNumber"=>""
                            ],
                            "FPriceListEntry"=>[
                                "FNumber"=>""
                            ],
                            "FARNOTJOINQTY"=>2.0,
                            "FQmEntryID"=>0,
                            "FConvertEntryID"=>0,
                            "FSOEntryId"=>0,
                            "FThirdEntryId"=>null,
                            "FBeforeDisPriceQty"=>0.0,
                            "FSignQty"=>0.0
                        ],
                        [
                            "FENTRYID"=>null,
                            "FRowType"=>"Standard",
                            "FCustMatID"=>[
                                "FNumber"=>""
                            ],
                            "FMaterialID"=>[
                                "FNumber"=>"019800036591"
                            ],
                            "FUnitID"=>[
                                "FNumber"=>"瓶"
                            ],
                            "FInventoryQty"=>0.0,
                            "FParentMatId"=>[
                                "FNumber"=>""
                            ],
                            "FRealQty"=>1.0,
                            "FDisPriceQty"=>0.0,
                            "FPrice"=>0.0,
                            "FTaxPrice"=>0.0,
                            "FIsFree"=>false,
                            "FBomID"=>[
                                "FNumber"=>""
                            ],
                            "FProduceDate"=>null,
                            "FOwnerTypeID"=>"BD_OwnerOrg",
                            "FOwnerID"=>[
                                "FNumber"=>"100"
                            ],
                            "FLot"=>[
                                "FNumber"=>""
                            ],
                            "FExpiryDate"=>null,
                            "FTaxCombination"=>[
                                "FNumber"=>""
                            ],
                            "FEntryTaxRate"=>17.00,
                            "FAuxUnitQty"=>0.0,
                            "FExtAuxUnitId"=>[
                                "FNumber"=>""
                            ],
                            "FExtAuxUnitQty"=>0.0,
                            "FStockID"=>[
                                "FNumber"=>"CK001"
                            ],
                            "FStockStatusID"=>[
                                "FNumber"=>"KCZT01_SYS"
                            ],
                            "FQualifyType"=>"",
                            "FMtoNo"=>null,
                            "FEntrynote"=>null,
                            "FDiscountRate"=>0.0,
                            "FActQty"=>0.0,
                            "FSalUnitID"=>[
                                "FNumber"=>"瓶"
                            ],
                            "FSALUNITQTY"=>1.0,
                            "FSALBASEQTY"=>1.0,
                            "FPRICEBASEQTY"=>1.0,
                            "FProjectNo"=>null,
                            "FOUTCONTROL"=>false,
                            "FRepairQty"=>0.0,
                            "FIsCreateProDoc"=>"",
                            "FEOwnerSupplierId"=>[
                                "FNumber"=>""
                            ],
                            "FIsOverLegalOrg"=>false,
                            "FESettleCustomerId"=>[
                                "FNumber"=>""
                            ],
                            "FPriceListEntry"=>[
                                "FNumber"=>""
                            ],
                            "FARNOTJOINQTY"=>1.0,
                            "FQmEntryID"=>0,
                            "FConvertEntryID"=>0,
                            "FSOEntryId"=>0,
                            "FThirdEntryId"=>null,
                            "FBeforeDisPriceQty"=>0.0,
                            "FSignQty"=>0.0
                        ],
                        [
                            "FENTRYID"=>null,
                            "FRowType"=>"Standard",
                            "FCustMatID"=>[
                                "FNumber"=>""
                            ],
                            "FMaterialID"=>[
                                "FNumber"=>"023400016204"
                            ],
                            "FUnitID"=>[
                                "FNumber"=>"罐"
                            ],
                            "FInventoryQty"=>0.0,
                            "FParentMatId"=>[
                                "FNumber"=>""
                            ],
                            "FRealQty"=>1.0,
                            "FDisPriceQty"=>0.0,
                            "FPrice"=>0.0,
                            "FTaxPrice"=>0.0,
                            "FIsFree"=>false,
                            "FBomID"=>[
                                "FNumber"=>""
                            ],
                            "FProduceDate"=>null,
                            "FOwnerTypeID"=>"BD_OwnerOrg",
                            "FOwnerID"=>[
                                "FNumber"=>"100"
                            ],
                            "FLot"=>[
                                "FNumber"=>""
                            ],
                            "FExpiryDate"=>null,
                            "FTaxCombination"=>[
                                "FNumber"=>""
                            ],
                            "FEntryTaxRate"=>17.00,
                            "FAuxUnitQty"=>0.0,
                            "FExtAuxUnitId"=>[
                                "FNumber"=>""
                            ],
                            "FExtAuxUnitQty"=>0.0,
                            "FStockID"=>[
                                "FNumber"=>"CK001"
                            ],
                            "FStockStatusID"=>[
                                "FNumber"=>"KCZT01_SYS"
                            ],
                            "FQualifyType"=>"",
                            "FMtoNo"=>null,
                            "FEntrynote"=>null,
                            "FDiscountRate"=>0.0,
                            "FActQty"=>0.0,
                            "FSalUnitID"=>[
                                "FNumber"=>"罐"
                            ],
                            "FSALUNITQTY"=>1.0,
                            "FSALBASEQTY"=>1.0,
                            "FPRICEBASEQTY"=>1.0,
                            "FProjectNo"=>null,
                            "FOUTCONTROL"=>false,
                            "FRepairQty"=>0.0,
                            "FIsCreateProDoc"=>"",
                            "FEOwnerSupplierId"=>[
                                "FNumber"=>""
                            ],
                            "FIsOverLegalOrg"=>false,
                            "FESettleCustomerId"=>[
                                "FNumber"=>""
                            ],
                            "FPriceListEntry"=>[
                                "FNumber"=>""
                            ],
                            "FARNOTJOINQTY"=>1.0,
                            "FQmEntryID"=>0,
                            "FConvertEntryID"=>0,
                            "FSOEntryId"=>0,
                            "FThirdEntryId"=>null,
                            "FBeforeDisPriceQty"=>0.0,
                            "FSignQty"=>0.0,
                            "FTaxDetailSubEntity"=>[
                                [
                                    "FDetailID"=>null,
                                    "FTaxRate"=>0.0
                                ]
                            ]
                        ]
                    ]
                ];
            return $this->save($data);
    }


    /**
    提交
     *
     * 1.formid：业务对象表单Id（必录）
    2.data：Json格式数据（详情参考Json格式数据）（必录）
    2.1.CreateOrgId：创建者组织，字符串类型（非必录）
    2.2.Numbers：单据编号集合，格式["billNo1","billNo1",...]，数组类型（必录）
     */

    public function  SubmitSalesRelease($Numbers=[]){
        return $this->submit($Numbers);
    }

    /**
    审核
     * 1.formid：业务对象表单Id（必录）
    2.data：Json格式数据（详情参考Json格式数据）（必录）
    2.1.CreateOrgId：创建者组织，字符串类型（非必录）
    2.2.Numbers：单据编号集合，格式["billNo1","billNo1",...]，数组类型（必录）
     */
    public function AuditSalesRelease($Numbers=[]){
        return $this->audit($Numbers);
    }


    /**
    反审核
     * 1.formid：业务对象表单Id（必录）
    2.data：Json格式数据（详情参考Json格式数据）（必录）
    2.1.CreateOrgId：创建者组织，字符串类型（非必录）
    2.2.Numbers：单据编号集合，格式["billNo1","billNo1",...]，数组类型（必录）
     */
    public function unAuditSalesRelease($Numbers=[]){
        return $this->unAudit($Numbers);
    }

    /**
     *单据列表查询
     * 1.data：Json格式数据（详情参考Json格式数据）（必录）
    1.1.FormId：业务对象表单Id（必录）
    1.2.FieldKeys：字段keys，字符串类型用逗号分隔，比如"key1,key2..."（必录）
    1.3.FilterString：过滤（非必录）  FNumber=''
    1.4.OrderString：排序字段（非必录）
    1.5.TopRowCount：总行数（非必录）
    1.6.StartRow：开始行（非必录）
    1.7.Limit：最大行数，不能超过2000（非必录）
     */
    public function ExecuteBillQuerySalesRelease($FieldKeys='',$FilterString='',$OrderString='',$TopRowCount=0,$StartRow=0,$Limit=20)
    {
            if (empty($FieldKeys)) {
                $FieldKeys='FBillNo,FCustomerID,FDocumentStatus,FCarriageNO,FCreatorId,FCreateDate';
            }
            return $this->ExecuteBillQuery($FieldKeys,$FilterString,$OrderString,$TopRowCount,$StartRow,$Limit);
    }


}